package com.sumi.erp.controller;

import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.core.page.TableDataInfo;
import com.sumi.common.enums.BusinessType;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.erp.domain.BaseWarehouseGroup;
import com.sumi.erp.service.IBaseWarehouseGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 虚拟仓库组Controller
 * 
 * @author fgf67@163.com
 * @date 2024-06-28
 */
@RestController
@RequestMapping("/erp/group")
public class BaseWarehouseGroupController extends BaseController
{
    @Autowired
    private IBaseWarehouseGroupService baseWarehouseGroupService;

    /**
     * 查询虚拟仓库组列表
     */
    @PreAuthorize("@ss.hasPermi('erp:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseWarehouseGroup baseWarehouseGroup)
    {
        startPage();
        List<BaseWarehouseGroup> list = baseWarehouseGroupService.selectBaseWarehouseGroupList(baseWarehouseGroup);
        return getDataTable(list);
    }

    /**
     * 导出虚拟仓库组列表
     */
    @PreAuthorize("@ss.hasPermi('erp:group:export')")
    @Log(title = "虚拟仓库组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseWarehouseGroup baseWarehouseGroup)
    {
        List<BaseWarehouseGroup> list = baseWarehouseGroupService.selectBaseWarehouseGroupList(baseWarehouseGroup);
        ExcelUtil<BaseWarehouseGroup> util = new ExcelUtil<BaseWarehouseGroup>(BaseWarehouseGroup.class);
        util.exportExcel(response, list, "虚拟仓库组数据");
    }

    /**
     * 获取虚拟仓库组详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:group:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseWarehouseGroupService.selectBaseWarehouseGroupById(id));
    }

    /**
     * 新增虚拟仓库组
     */
    @PreAuthorize("@ss.hasPermi('erp:group:add')")
    @Log(title = "虚拟仓库组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseWarehouseGroup baseWarehouseGroup)
    {
        return toAjax(baseWarehouseGroupService.insertBaseWarehouseGroup(baseWarehouseGroup));
    }

    /**
     * 修改虚拟仓库组
     */
    @PreAuthorize("@ss.hasPermi('erp:group:edit')")
    @Log(title = "虚拟仓库组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseWarehouseGroup baseWarehouseGroup)
    {
        return toAjax(baseWarehouseGroupService.updateBaseWarehouseGroup(baseWarehouseGroup));
    }

    /**
     * 删除虚拟仓库组
     */
    @PreAuthorize("@ss.hasPermi('erp:group:remove')")
    @Log(title = "虚拟仓库组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseWarehouseGroupService.deleteBaseWarehouseGroupByIds(ids));
    }
}
